<template>
	<view>
	<!-- 	<view @click="getAddress(3)" class="flex-row items-center group_4 view_2 space-x-26">



		</view> -->


	<!-- 	<view  @click="getAddress(3)" class="flex-row justify-between  items-center     items-start  padding-10 margin " style="width:100%">
				<text    class="font_2" style="flex:4;">请选择地址</text>
				<view   style="flex:8; text-decoration: underline;" >请选择</view>
				<u-icon  style="flex:1;width:190rpx;" class="flex justify-between align-center items-start" name="arrow-right" ></u-icon>
		</view> -->
	<view  @click="getAddress(3)" class="flex-row justify-between  items-center     items-start  padding-10 margin " style="width:100%">
			<text class="font_2" style="width:190rpx;">请选择地址</text>

				<view class="flex-1 flex-row items-center    justify-between  items-start  padding-10 " style="">
							<view   style="text-decoration: underline;">{{hyend.name?hyend.name:'请选择'}}</view>
							<u-icon  class="flex justify-between align-center items-start" name="arrow-right" ></u-icon>
				</view>

	</view>


	<view class="flex-row items-center    justify-start items-start  padding-10 margin " style="width:100%;align-content:stretch">
			<text class="font_2" style="width:190rpx;">详细地址</text>
			<view class="flex-1 flex-row items-center    justify-between  items-start  padding-10 " style="">
					<input  v-model="addressinfo" placeholder="详细地址（选填）"  style="flex:1">

					<u-icon   class="flex justify-between align-center items-start" name="arrow-right" ></u-icon>
			 </view>
	</view>

	<!-- <view class="flex-row items-center    justify-start items-start  padding-10 " style="width:100%">
			<text class="font_2" style="width:190rpx;">门牌号（选填）</text>
			<view class="flex-1 flex-row items-center    justify-between  items-start  padding-10 " style="">
					<input  v-model="code" placeholder="请输入门牌号）">

					<u-icon  class="flex justify-between align-center items-start" name="arrow-right" ></u-icon>
			 </view>
	</view> -->

	<view class="flex-row items-center    justify-start items-start  padding-10 " style="width:100%">
			<text class="font_2" style="width:190rpx;">*联系人</text>
			<view class="flex-1 flex-row items-center    justify-between  items-start  padding-10 " style="">
					<input  v-model="contacts" placeholder="请输入联系人（必填）">

					<u-icon  class="flex justify-between align-center items-start" name="arrow-right" ></u-icon>
			 </view>
	</view>
	<view class="flex-row items-center    justify-start items-start  padding-10 " style="width:100%">
			<text class="font_2" style="width:190rpx;">*联系电话</text>
			<view class="flex-1 flex-row items-center    justify-between  items-start  padding-10 " style="">
					<input  v-model="tel" placeholder="请输入手机号（必填）">

					<u-icon  class="flex justify-between align-center items-start" name="arrow-right" ></u-icon>
			 </view>
	</view>



<!-- 		<u--input v-model="floor" label="楼层" placeholder="请输入楼层（选填）">
			<u-icon name="arrow-right" slot="right"></u-icon>
		</u--input>
		<u--input v-model="code" label="门牌号" placeholder="请输入门牌号（选填）">
			<u-icon name="arrow-right" slot="right"></u-icon>
		</u--input>
		<u--input v-model="tel" type="tel" label="联系电话" placeholder="请输入手机号（选填）">
			<u-icon name="arrow-right" slot="right"></u-icon>
		</u--input> -->
		<view class="fixed-bottom pd-36">
			<u-button v-if="index" class="pb-20" type="" @click="delAddr">删除收货地信息</u-button>
			<view style="height: 20rpx;"></view>
			<u-button type="primary" @click="addAddr">确认收货地信息</u-button>
		</view>
	</view>
</template>

<script>
	import {
		checkPhone
	} from '@/utils/libs/uniApi.js'
	import {mapState} from 'vuex'
	export default {
		data() {
			return {
				type :1,
				floor: '',
				code: '',
				contacts:'',
				tel: '',
				index:'', //编辑地址索引
			};
		},
		computed:{
			...mapState(["start","hyend"]),
			addressinfo(){
				return this.hyend.address
			},
		},

		onLoad(option) {
			this.type = option.type
			this.location = option.location
			this.list = this.address
		},
		beforeDestroy() {
			this.$store.commit('getHyEnd',{})
		},
		methods:{
			getAddress(type) {
				console.log(type)
				console.log( '/pages/ys/search?type=' + type + '&location=' + location)
				uni.navigateTo({
					url: '/pages/ys/search?type=' + type + '&location=' + location
				})
			},
			addAddr(){

				   console.log("hyend",this.hyend)
				   
				   
				if(!this.hyend.name){
					uni.showToast({
						title:'请选择收货地址',
						icon:'none'
					})
				}else{


						if(!this.contacts){
							uni.showToast({
								title:'请填写联系人',
								icon:'none'
							})
							return
						}

						if(!this.tel){
							uni.showToast({
								title:'请填写联系人电话',
								icon:'none'
							})
							return
						}


						if(!checkPhone(this.tel)){
							uni.showToast({
								title:'请填写正确的电话',
								icon:'none'
							})
							return
						}


					let addr={
						address:this.hyend,
						addressinfo:this.addressinfo,
						// floor: this.floor,
						// code: this.code,
						contacts:this.contacts,
						tel:this.tel
					}
								console.log("addraddraddraddraddraddraddraddraddraddr");
					console.log(addr);
						console.log("this.type，",this.type);
					
					console.log("this.type",this.type)
					if(this.type==1){
							uni.setStorageSync('tyAddressFrom', addr);
						
							this.$store.commit('getaddressFrom',addr)
					}else if(this.type==2){
							uni.setStorageSync('tyAddressTo',addr);
							this.$store.commit('getaddressTo',addr)
					}
					// this.$store.commit('getTyAddressFrom',addr)

					// this.$store.commit('getTyAddressTo',addr)


					// this.$store.commit('getHyAddress',addr)
					// this.$store.commit('getHyEnd',{})

					// clear this form
	
					uni.navigateBack({
						delta: 1
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.u-primary-hover {
		background: linear-gradient(to right,#00b6b4,#00d496) !important;
	}
</style>
